<template>
	<view class="rentgrab">
		<view class="navlist">
			<view :class="isActive == index ?'nav_item active':'nav_item'" v-for="(item,index) in navlist" :key="index"
				@click="changeNav(index)">
				{{item.text}}
			</view>
		</view>
		<view class="shoplist">
			<view class="nonelist" v-if="orderlist.length == 0">
				<view class="shop_text">
					-- 暂无订单 --
				</view>
			</view>
			<view class="" v-else>
				<view class="shop_item" v-for="(item,index) in orderlist" :key="index"
					@click="toPage('./detail?id='+item.order_no)">
					<view class="title">
						<view class="left">
							<text>订单号 :</text>
							<text>{{item.order_no}}</text>
						</view>
						<text class="order_type">{{item.state_text}}</text>
					</view>
					<view class="infobox" v-for="(goods,index) in item.goods" :key="goods.id">
						<image :src="goods.goods_info.cover_path" mode=""></image>
						<view class="right">
							<view class="infoli">
								<text class="infotitle">{{goods.goods_info.name}}</text>
							</view>
							<view class="infoli">
								<text class="infotitle price red">￥{{goods.goods_price}}</text>
								<text class="infotitle price">×{{goods.total_num}}/{{goods.goods_info.unit}}</text>
							</view>
						</view>
					</view>
					<view class="infobot money">
						<text style="color: #777;">下单时间：{{item.create_time}}</text>
						<text>金额：{{item.pay_amount}}</text>
					</view>
					<view class="infobot">
						<text class="type" v-if="item.show_delivery"
							@click.stop="toPage('./delivery?id='+item.order_no)">去发货</text>
						<text class="type">查看详情</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		orderlst
	} from "@/api/user.js"
	export default {
		data() {
			return {
				isActive: 0,
				navlist: [{
						text: '全部',
						type: 'all'
					},
					{
						text: '待付款',
						type: 'payment'
					},
					{
						text: '待发货',
						type: 'delivery'
					},
					{
						text: '待收货',
						type: 'receipt'
					},
					{
						text: '已完成',
						type: 'comment'
					}
				],
				config: [],
				status: '5',
				orderlist: [],
				page: 1,
				last_page: 1
			}
		},
		components: {},
		onLoad(e) {
			if (e.id) {
				this.isActive = e.id
			}
		},
		onShow() {
			this.page = 1
			this.last_page = 1
			this.orderlist = []
			this.getData()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.getData()
			}
		},
		methods: {
			toPage(url) {
				uni.navigateTo({
					url
				})
			},
			changeNav(index) {
				this.isActive = index
				this.page = 1
				this.getData()
			},
			getData() {
				this.orderlist = []
				uni.showLoading({
					mask: true
				})
				orderlst({
					type: this.navlist[this.isActive].type,
					page: this.page
				}).then(res => {
					uni.hideLoading()
					if (res.code == 0) {
						this.orderlist = this.orderlist.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			},
			refund(id) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确认退款吗?',
					success(res) {
						if (res.confirm) {
							refund({
								id
							}).then(res => {
								uni.$showMsg(res.msg)
								if (res.code == 0) {
									that.isActive = 0;
									that.getData()
								}
							})
						}
					}
				})
			},

		}
	}
</script>

<style lang="scss">
	.rentgrab {
		background-color: #f2f2f2;
		min-height: 100vh;
		height: 100%;

		.back_red {
			background-color: $uni-bg-color;
			color: #fff;
		}

		.back_green {
			background-color: green;
			color: #fff;
		}

		.navlist {
			display: flex;
			justify-content: space-between;
			position: fixed;
			top: 0;
			/* #ifdef H5 */
			top: 44px;
			/* #endif */
			width: 100%;
			max-width: 500px;
			z-index: 999;
			background: $uni-bg-color;

			.nav_item {
				width: 25%;
				text-align: center;
				color: #ffffff80;
				height: 40px;
				justify-content: center;
				// line-height: 50px;
				font-weight: bold;
				display: flex;
				flex-direction: column;
				font-size: 14px;
			}

			.active {
				color: #fff;
				position: relative;
			}

			.active::after {
				position: absolute;
				content: '';
				width: 25px;
				height: 3px;
				background: #fff;
				left: 50%;
				bottom: 4px;
				transform: translate(-50%);
			}
		}

		.shoplist {
			padding-top: 50px;

			.shop_text {
				text-align: center;
				color: #999;
				font-size: 14px;
				padding: 30px 0;
			}

			.shop_item {
				background: #fff;
				margin-top: 15px;
				width: 96%;
				margin: 10px auto;
				border-radius: 5px;
				box-sizing: border-box;
				padding: 5px 0;
				border-bottom: 5px solid #f8f8f8;

				.title {
					color: #000;
					font-size: 14px;
					padding: 10px;
					border-bottom: 1px solid #f3f3f3;
					display: flex;
					align-items: center;
					justify-content: space-between;

					text {
						margin-right: 5px;
					}

					.order_type {
						color: $uni-bg-color;
					}
				}

				.infobox {
					display: flex;
					align-items: center;
					padding: 10px;
					box-sizing: border-box;


					image {
						width: 120upx;
						height: 120upx;
						border-radius: 5px;
					}

					.right {
						flex: 1;

						.infoli {
							padding: 0 10px;
							font-size: 12px;
							color: #000;
							margin-top: 5px;
							display: flex;
							justify-content: space-between;

							.infotitle {
								font-size: 14px;
								font-weight: 550;
							}


							.price {
								font-weight: 500;
								font-size: 12px;
								margin-top: 5px;
								color: #333;
							}


							text {
								margin-right: 5px;
							}
						}
					}

				}

				.infobot {
					display: flex;
					align-items: center;
					justify-content: flex-end;
					border-top: 1px solid #f3f3f3;
					padding: 5px 10px;
					color: #000;
					font-size: 14px;

					.type {
						background-color: $uni-bg-color;
						color: #fff;
						padding: 5px 10px;
						border-radius: 5px;
						margin-left: 8px;
						font-size: 12px;
					}

					.type_1 {
						background-color: #fff;
						border: 1px solid $uni-bg-color;
						color: $uni-bg-color;
					}
				}

				.money {
					display: flex;
					justify-content: space-between;
					color: $uni-bg-color;
					font-size: 12px;
					font-weight: bold;
				}

				.buytime {
					display: table;
					width: 100%;
					font-size: 12px;
					box-sizing: border-box;

					text {
						float: left;
						margin: 0px 4% 0px 0;
					}
				}
			}
		}
	}
</style>